# coding=utf-8
#================================================================
#   Copyright (C) 2020 * Ltd. All rights reserved.
#
#   File name   : service.py
#   Author      : ZouZheKang-1996
#   Created date: 2020-08-14 18:50:44
#   Description : XuQingQing,I really ❤ U！
#
#================================================================

import io
import numpy as np
from PIL import Image
from flask import Flask, request, jsonify
import flask
import os
import tensorflow as tf
os.environ["CUDA_VISIBLE_DEVICES"] = "-1"

app = Flask(__name__)

@app.route("/predict", methods=["POST"])
def predict():

    data = {"success": False}

    if flask.request.method == "POST":
        print("roger_that")
        if flask.request.files.get("image"):
            # 转换回图片
            image = request.files["image"].read()
            image = Image.open(io.BytesIO(image))
            ##### 这里填预测过程：#####
            
            #ex: res = model.predict(image)
            #ex: data["predictions"] = []
            #ex: data["predictions"].append(res))

            ########################### 
            data["success"] = True
    return jsonify(data)
    
if __name__ == "__main__":
    print(("* Loading Keras model and Flask starting server..."
        "please wait until server has fully started"))
    app.run(host='172.16.1.167', port =5000 )